﻿Imports System.Configuration

Namespace Connection

    Public Class KairyuSectionHandler
        Inherits ConfigurationSection

        ''' <summary>
        ''' 実行環境要素
        ''' </summary>
        <ConfigurationProperty("execution-env", IsRequired:=True)> _
        Public Property ExecutionEnvironment() As ExecutionEnvironmentElement
            Get
                Return DirectCast(MyBase.Item("execution-env"), ExecutionEnvironmentElement)
            End Get
            Set(value As ExecutionEnvironmentElement)
                MyBase.Item("execution-env") = value
            End Set
        End Property

        ''' <summary>
        ''' 環境要素リスト
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <ConfigurationProperty("databases")> _
        Public ReadOnly Property Databases() As DatabaseElementCollection
            Get
                Dim lst As DatabaseElementCollection = DirectCast(Me("databases"), DatabaseElementCollection)
                Return lst
            End Get
        End Property

        ''' <summary>
        ''' 実行環境DB名を取得します。
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetCurrentDatabaseName() As String
            Return Me.ExecutionEnvironment.Database
        End Function

        ''' <summary>
        ''' 実行環境DBを取得します。
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetCurrentDatabase() As DatabaseElement
            Dim name = Me.GetCurrentDatabaseName
            Return Me.GetDatabase(name)
        End Function

        ''' <summary>
        ''' 任意の環境DBを取得します。
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function GetDatabase(name As String) As DatabaseElement
            Return Me.Databases.GetDatabase(name)
        End Function
    End Class

End Namespace
